package com.wq.myspring.eventmode;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;

/**
 * @PackageName: com.wq.myspring.eventmode
 * @ClassName EventSource
 * @Description: TODO 事件源(注册监听器，发布事件)
 * @Author Wenqiang
 * @Date 2021/07/18 0:35
 * @Version V1.0
 */
public class EventSource {
	private Set<EventListener> listenerSet = new HashSet<EventListener>();

	public void register(EventListener listener) {
		listenerSet.add(listener);
	}

	public void publishEvent(Event e) {
		listenerSet.stream().forEach(i -> {
			i.eventProcess(e);
		});
	}

}
